using UnityEngine;
using UnityEngine.UI;

public class UIShopItem : MonoBehaviour
{
	public Image imgIcon;

	public Text txtName;

	public Text txtDesc;

	public Text txtPrice;

	public Text txtNumber;

	public Text stopSelling;

	public Text stockAndHave;

	private ShopInfo _shopInfo;

	public GameObject btnGO;

	public UIShopPanel parentPanel
	{
		get;
		set;
	}

	public ShopInfo shopInfo
	{
		set
		{
			_shopInfo = value;
			if (!parentPanel.commonPanel.activeSelf)
			{
				return;
			}
			txtName.text = value.itemInfo.name;
			txtDesc.text = value.itemInfo.desc;
			txtPrice.text = value.price + string.Empty;
			imgIcon.sprite = LaunchUIController.instance.GetSpriteFromName(value.itemInfo.icon);
			if (value.itemInfo.type == 0)
			{
				stockAndHave.text = "库存:";
				int num = _shopInfo.count - ShopInfoMgr.GetBuyCount(_shopInfo.id);
				txtNumber.text = ((num < 0) ? "0" : num.ToString());
				if (num <= 0)
				{
					stopSelling.gameObject.SetActive(value: true);
					btnGO.SetActive(value: false);
				}
			}
			else
			{
				stockAndHave.text = "拥有:";
				Item item = ItemMgr.instance.GetItem(_shopInfo.itemId);
				txtNumber.text = ((item == null) ? "0" : (item.count + string.Empty));
			}
		}
	}

	private void Start()
	{
		if (stopSelling != null)
		{
			stopSelling.gameObject.SetActive(value: false);
		}
	}

	private void Update()
	{
	}

	public virtual void OnClickBuy()
	{
		if (_shopInfo == null)
		{
			return;
		}
		if (ConstantData.chips >= _shopInfo.price)
		{
			int num = ItemMgr.instance.AddItem(_shopInfo.itemId);
			ConstantData.chips -= _shopInfo.price;
			int num2 = ShopInfoMgr.AddBuyCount(_shopInfo.id);
			if (_shopInfo.itemInfo.type == 0)
			{
				if (num2 >= _shopInfo.count)
				{
					stopSelling.gameObject.SetActive(value: true);
					btnGO.SetActive(value: false);
				}
				int num3 = _shopInfo.count - num2;
				if (num3 >= 0)
				{
					txtNumber.text = num3 + string.Empty;
				}
			}
			else if (num > 0)
			{
				txtNumber.text = num + string.Empty;
			}
			parentPanel.OpenConfirmWnd(_shopInfo.itemInfo);
		}
		else
		{
			UnityEngine.Debug.Log("筹码不够");
			parentPanel.OpenNotEnoughWnd();
		}
	}
}
